<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">

      <el-form-item label="日期" prop="finaDate">
        <el-date-picker type="daterange" v-model="finaDate" format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd" :style="{width: '100%'}" start-placeholder="开始日期" end-placeholder="结束日期"
                  range-separator="至" clearable></el-date-picker>
      </el-form-item>




      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
       
      </el-form-item>
    </el-form>

    <el-tabs type="border-card" >

      <el-tab-pane label="觅康账户余额">
        <!--  -->
        <el-table v-loading="loading" :data="countList" border :span-method="arraySpanMethod"
         :row-class-name="tableRowClassName" show-summary :summary-method="getCountSummaries" style="font-size: 16px;">
          <el-table-column label="账户编码" align="center" prop="finaCode" />
          <el-table-column label="账户总收入" align="center" prop="totalIn" />
          <el-table-column label="账户总支出" align="center" prop="totalOut" />
          <el-table-column label="账户余额" align="center" prop="accountBalance" />
          <el-table-column label="一级科目" align="center" prop="subName1" />
          <el-table-column label="余额" align="center" prop="balance" />
        </el-table>

      </el-tab-pane>
    </el-tabs>


  </div>
</template>

<script>
  import { balanceList,countList } from "@/api/fina/cash";
  import { listSub,listByOrder } from "@/api/fina/sub";
  import {genCode} from "@/api/system/autocode/rule"

  export default {
    name: "Cash",
    dicts: ['cash_opter'],
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 出纳管理列表格数据
        cashList: [],
        //日期范围
        finaDate: [],
        //出纳统计汇总
        cashBalanceList: [],
        //经办人统计汇总
        countList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 收入显示
        inShow:true,
        // 支出显示
        outShow:true,
        // 用途显示
        finaAbstractShow:false,
        // 客户名称显示
        cusNameShow:false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          finaCode: null,
          finaDate: null,
          finaDateStart: null,
          finaDateEnd: null,
          subId1: null,
          subName1:null,
          subId2: null,
          subName2:null,
          subId3: null,
          subName3:null,
          subId4: null,
          subName4:null,
          orderNum: null,
          finaAbstract: null,
          finaOperatorId: null,
          finaOperatorName: null,
          finaIn: null,
          finaOut: null,
          finaBalance: null,
          status: null,
        },
        // 表单参数
        form: {},
        //弹框的操作类型 view add edit
        optType: undefined,
        //自动生成物料编码标识
        autoGenFlag: false,
        //是否海洋科技
        opteratorIsHY:false,
        //所有科目列表
        subAllOptions:[],
        //科目一列表
        sub1Options: [],
        //科目二列表
        sub2Options: [],
        //科目三列表
        sub3Options: [],
        //科目四列表
        sub4Options: [],
        //科目四列表
        finaAbstractOptions: [],
        //科目一选中id
        sub1IdSel:0,
        //科目2选中id
        sub2IdSel:0,
        //科目3选中id
        sub3IdSel:0,
        //科目4选中id
        sub4IdSel:0,
        //经办人总列表
        cashOpter: [],
        //经办人使用列表
        cashOpterUse: [],
        //经办人-1号仓
        cashOpter1: [],
        //经办人-2号仓
        cashOpter2: [],
        //经办人-借还仓
        cashOpter3: [],
        spanTableRow: {},
        balance1 : 0.00, //余额1
        balance2 : 0.00, //余额2
        balance3 : 0.00, //余额3
        balance4 : 0.00, //余额4
        //spanArr用于存放每一行记录的合并数
        spanArr: [],
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询出纳管理列列表 */
      getList() {
        this.loading = true;
        if(this.finaDate != undefined && this.finaDate != null && this.finaDate.length>0){
          // console.log("finaDate>>>",this.finaDate)
          this.queryParams.finaDateStart = this.finaDate[0]
          this.queryParams.finaDateEnd = this.finaDate[1]
        }
        /** 获取统计报表 */
        countList(this.queryParams).then(response => {
          // console.log("response.data>>>",JSON.stringify(response.data))
          this.countList = this.getCountList(response.data)

          this.loading = false;
        });
      },
      //经办人统计算法
      getCountList(data){

        var totalInAll = 0.00
        var totalOutAll = 0.00

        var countListTemp = []
        var countItem0 = {"finaCode":"海洋科技","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"短期借款","balance":0.00}
        var countItem1 = {"finaCode":"MK9813","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"觅康工商","balance":0.00}
        var countItem2 = {"finaCode":"MK5255","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"觅康农商","balance":0.00}
        var countItem3 = {"finaCode":"JM-XGM","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"匠觅小规模","balance":0.00}
        var countItem4 = {"finaCode":"MKcode","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"觅康收款码","balance":0.00}
        var countItem5 = {"finaCode":"SMK6217","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"觅康2号仓","balance":0.00}
        var countItem6 = {"finaCode":"MKXJ","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"觅康2号仓","balance":0.00}
        var countItem7 = {"finaCode":"JMXJ","totalIn":0.00,"totalOut":0,"accountBalance":0.00,"subName1":"短期借款","balance":0.00}
        var countItem8 = {"finaCode":"SJM3649","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"短期借款","balance":0.00}
        var countItem9 = {"finaCode":"JM1781","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"短期借款","balance":0.00}
        var countItem10 = {"finaCode":"YM1348","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"短期借款","balance":0.00}
        var countItem11 = {"finaCode":"MK-XGM","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"觅康小规模","balance":0.00}
        var countItem12 = {"finaCode":"CGcode","totalIn":0.00,"totalOut":0.00,"accountBalance":0.00,"subName1":"采购卡","balance":0.00}

        if(data!=undefined && data!=null && data.length>0){
          for(let i=0;i<data.length;i++){
            var item = data[i]
            if(item != undefined && item != null){

              var accountBalanceTemp = Number(item.finaBalance).toFixed(2)*1
              if(accountBalanceTemp == undefined || accountBalanceTemp == null){
                accountBalanceTemp = 0
              }
              var totalIn = Number(item.finaIn).toFixed(2)*1
              if(totalIn == undefined || totalIn == null){
                totalIn = 0
              }
              var totalOut = Number(item.finaOut).toFixed(2)*1
              if(totalOut == undefined || totalOut == null){
                totalOut = 0
              }
              var finaOperatorName = item.finaOperatorName.replace(/\s+/g,'')

              if(finaOperatorName === "海洋科技"){

                countItem0.accountBalance  = Number(Number(countItem0.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem0.balance  = Number(Number(countItem0.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem0.totalIn = Number(Number(countItem0.totalIn).toFixed(2)*1 + totalIn).toFixed(2)*1
                countItem0.totalOut  = Number(Number(countItem0.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1

                // this.balance1 += countItem0.accountBalance
              }
              if(finaOperatorName === "MK9813"){
                countItem1.accountBalance  = Number(Number(countItem1.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem1.balance  = Number(Number(countItem1.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem1.totalIn  = Number(Number(countItem1.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem1.totalOut  = Number(Number(countItem1.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1

                // this.balance2 += countItem1.accountBalance
              }
              if(finaOperatorName == "MK5255"){
                countItem2.accountBalance  = Number(Number(countItem2.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem2.balance  = Number(Number(countItem2.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem2.totalIn  = Number(Number(countItem2.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem2.totalOut  = Number(Number(countItem2.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1
                // this.balance2 +=  accountBalanceTemp

                // this.balance2 += countItem2.accountBalance
              }
              if(finaOperatorName == "MKcode"){
                countItem4.accountBalance  = Number(Number(countItem4.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem4.bBalance  = Number(Number(countItem4.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem4.totalIn  = Number(Number(countItem4.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem4.totalOut  = Number(Number(countItem4.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1
                // this.balance2 +=   countItem4.accountBalance
          // console.log("23>>>>>",this.balance2)
              }
              if(finaOperatorName == "SMK6217"){
                countItem5.accountBalance  = Number(Number(countItem5.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem5.balance  = Number(Number(countItem5.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem5.totalIn  = Number(Number(countItem5.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem5.totalOut  = Number(Number(countItem5.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1
                // this.balance2  += countItem5.accountBalance
          // console.log("24>>>>>",this.balance2)
              }
              if(finaOperatorName == "MKXJ"){
                countItem6.accountBalance  =Number( Number(countItem6.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem6.balance  = Number(Number(countItem6.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem6.totalIn  = Number(Number(countItem6.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem6.totalOut  = Number(Number(countItem6.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1
                // this.balance2  += countItem6.accountBalance
          // console.log("25>>>>>",this.balance2)
              }

              if(finaOperatorName == "JM-XGM"){
                countItem3.accountBalance  = Number(Number(countItem3.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem3.balance  = Number(Number(countItem3.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem3.totalIn  = Number(Number(countItem3.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem3.totalOut  = Number(Number(countItem3.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1
                // this.balance2 +=  countItem3.accountBalance
          // console.log("22>>>>>",this.balance2)
              }

              if(finaOperatorName == "JMXJ"){
                countItem7.accountBalance = Number(Number(countItem7.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem7.balance = Number(Number(countItem7.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem7.totalIn = Number(Number(countItem7.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem7.totalOut = Number(Number(countItem7.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1

                // this.balance3  += countItem7.accountBalance
              }
              if(finaOperatorName == "SJM3649"){
                countItem8.accountBalance = Number(Number(countItem8.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem8.balance = Number(Number(countItem8.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem8.totalIn = Number(Number(countItem8.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem8.totalOut = Number(Number(countItem8.totalOut).toFixed(2)*1 +totalOut).toFixed(2)*1
                // this.balance3 += countItem8.accountBalance
              }
              if(finaOperatorName == "JM1781"){
                countItem9.accountBalance = Number(Number(countItem9.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem9.balance = Number(Number(countItem9.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem9.totalIn = Number(Number(countItem9.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem9.totalOut = Number(Number(countItem9.totalOut).toFixed(2)*1  + totalOut).toFixed(2)*1
                // this.balance3 += countItem9.accountBalance
              }
              if(finaOperatorName == "YM1348"){
                countItem10.accountBalance = Number(Number(countItem10.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem10.balance = Number(Number(countItem10.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem10.totalIn = Number(Number(countItem10.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem10.totalOut = Number(Number(countItem10.totalOut).toFixed(2)*1  + totalOut).toFixed(2)*1
                // this.balance3 += countItem9.accountBalance
              }
              if(finaOperatorName == "MK-XGM"){
                countItem11.accountBalance = Number(Number(countItem11.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem11.balance = Number(Number(countItem11.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem11.totalIn = Number(Number(countItem11.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem11.totalOut = Number(Number(countItem11.totalOut).toFixed(2)*1  + totalOut).toFixed(2)*1
                // this.balance3 += countItem9.accountBalance
              }
              if(finaOperatorName == "CGcode"){
                countItem12.accountBalance = Number(Number(countItem12.accountBalance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem12.balance = Number(Number(countItem12.balance).toFixed(2)*1+accountBalanceTemp).toFixed(2)*1
                countItem12.totalIn = Number(Number(countItem12.totalIn).toFixed(2)*1 +totalIn).toFixed(2)*1
                countItem12.totalOut = Number(Number(countItem12.totalOut).toFixed(2)*1  + totalOut).toFixed(2)*1
                // this.balance3 += countItem9.accountBalance
              }
            }
          }
          // countItem0.accountBalance = this.balance1
          // countItem1.accountBalance = this.balance2
          // countItem2.accountBalance = this.balance2
          // console.log("1>>>>>",Number(this.balance1).toFixed(2))
          // console.log("2>>>>>",this.balance2)
          // console.log("3>>>>>",this.balance3)
          this.balance1 = countItem0.accountBalance
          this.balance2 = countItem1.accountBalance+countItem2.accountBalance+countItem4.accountBalance+countItem11.accountBalance
          +countItem5.accountBalance+countItem6.accountBalance+countItem12.accountBalance
          this.balance3 = countItem7.accountBalance+countItem8.accountBalance+countItem9.accountBalance+countItem3.accountBalance+countItem10.accountBalance
          // console.log("2>>>>>",this.balance2)

          // this.balance4 = countItem12.accountBalance

          this.$set(countItem0,"balance",Number(this.balance1).toFixed(2)*1)
          this.$set(countItem1,"balance",Number(this.balance2).toFixed(2)*1)
          this.$set(countItem2,"balance",Number(this.balance2).toFixed(2)*1)
          this.$set(countItem4,"balance",Number(this.balance2).toFixed(2)*1)
          this.$set(countItem5,"balance",Number(this.balance2).toFixed(2)*1)
          this.$set(countItem6,"balance",Number(this.balance2).toFixed(2)*1)
          this.$set(countItem11,"balance",Number(this.balance2).toFixed(2)*1)
          this.$set(countItem12,"balance",Number(this.balance2).toFixed(2)*1)
          this.$set(countItem3,"balance",Number(this.balance3).toFixed(2)*1)
          this.$set(countItem7,"balance",Number(this.balance3).toFixed(2)*1)
          this.$set(countItem8,"balance",Number(this.balance3).toFixed(2)*1)
          this.$set(countItem9,"balance",Number(this.balance3).toFixed(2)*1)
          this.$set(countItem10,"balance",Number(this.balance3).toFixed(2)*1)

          countListTemp.push(countItem0)
          countListTemp.push(countItem1)
          countListTemp.push(countItem2)
          countListTemp.push(countItem4)
          countListTemp.push(countItem5)
          countListTemp.push(countItem6)
          countListTemp.push(countItem11)
          countListTemp.push(countItem12)
          countListTemp.push(countItem3)
          countListTemp.push(countItem7)
          countListTemp.push(countItem8)
          countListTemp.push(countItem9)
          countListTemp.push(countItem10)
          // console.log("countItem1:::",countItem1)

        }
        // console.log("countListTemp>>>",countListTemp)
        return countListTemp
      },
      getCountSummaries(res){
        const { columns, data } = res
        // console.log(columns, res);
        const sum = []
        columns.forEach((element, index) => {
          if (index == 0) {
            sum[index] = '合计'
          }
          if (index == 1) {
             sum[index] = data.reduce((pre, cur) => pre + Number(cur.totalIn), 0)
             sum[index] = sum[index].toFixed(2)
          }
          if (index == 2) {
            //cur.wxAmount  合计对象的数字
             sum[index] = data.reduce((pre, cur) => pre + Number(cur.totalOut), 0)
             sum[index] = sum[index].toFixed(2)
          }
          if (index == 3) {
            //cur.wxAmount  合计对象的数字
             sum[index] = data.reduce((pre, cur) => pre + Number(cur.accountBalance), 0)
             sum[index] = sum[index].toFixed(2)
          }
          if (index == 4) {
            sum[index] = '合计'
          }
          if (index == 5) {
            //cur.wxAmount  合计对象的数字
             sum[index] = data.reduce((pre, cur) => pre + Number(cur.accountBalance), 0)
             sum[index] = sum[index].toFixed(2)
          }
        });
        return sum

      },
      getSummaries(res){
        const { columns, data } = res
        // console.log(columns, res);
        const sum = []
        columns.forEach((element, index) => {
          if (index == 1) {
            sum[index] = '合计'
          }
          if (index == 9) {
            //cur.wxAmount  合计对象的数字
             sum[index] = data.reduce((pre, cur) => pre + Number(cur.finaIn), 0)
             sum[index] = sum[index].toFixed(2)
          }
          if (index == 10) {
            //cur.wxAmount  合计对象的数字
             sum[index] = data.reduce((pre, cur) => pre + Number(cur.finaOut), 0)
             sum[index] = sum[index].toFixed(2)
          }
          if (index == 11) {
            //cur.wxAmount  合计对象的数字
             sum[index] = data.reduce((pre, cur) => pre + Number(cur.finaBalance), 0)
             sum[index] = sum[index].toFixed(2)
          }
        });
        return sum

      },
      /** 获取科目下拉列表 */
      getSubList(){
        listSub(null).then(response => {
          // debugger;
          var data = response.rows
          this.subAllOptions = data
          // console.log("data::::",data)
          for(let i=0;i<data.length;i++){
            var item = data[i]
            // console.log("item::::",item)
            var orderNum = item.orderNum
            if(orderNum == 1){
              this.sub1Options.push(item)
            }
            else if(orderNum == 2){
              this.sub2Options.push(item)
            }else if(orderNum == 3){
              this.sub3Options.push(item)
            }else if(orderNum == 4){
              this.sub4Options.push(item)
            }
          }
        });



      },
      /** 根据上一级获取对应下一级列表 */
      getSubListBySubId(row,subId){
        var data = this.subAllOptions
        var subOptions = []
        var subName = ""
        for(let i=0;i<data.length;i++){
          var item = data[i]
          if(item.subId == subId){
            subName = item.subName
          }
          // console.log("item::::",item)
          var orderNum = item.orderNum
          if(row == 2){
            if(item.subId == subId){
              this.form.subName1 = item.subName
            }
          }else if(row == 3){
            if(item.subId == subId){
              this.form.subName2 = item.subName
            }
          }else if(row == 4){
            if(item.subId == subId){
              this.form.subName3 = item.subName
              if(item.subName == "海洋科技"){
                this.form.finaOperatorId = 1001
                this.form.finaOperatorName = "海洋科技"
                // this.form.finaOperatorName = {"key":1001,"label":"海洋科技","value":1001}
                this.opteratorIsHY = true
                this.rules.finaOperatorName[0].required = false
              }
              else{
                this.opteratorIsHY = false
              //   this.form.finaOperatorName = ""
                this.rules.finaOperatorName[0].required = true
              }
            }

          }else if(row == 5){
              if(item.subId == subId){
                this.form.subName4 = item.subName
              }
          }
          if(item.parentId == subId){
            subOptions.push(item)
          }

        }

        if(row == 2){

          if(subId == 101){//应收
            this.inShow = true
            this.outShow = false
            this.rules.finaIn[0].required = true
            this.rules.finaOut[0].required = false
          }else if(subId == 102){// 应付
            this.inShow = false
            this.outShow = true
            this.rules.finaIn[0].required = false
            this.rules.finaOut[0].required = true
          }

          this.form.subId2 = null
          this.form.subId3 = null
          this.form.subId4 = null
          this.form.finaAbstract = null
          this.sub2Options = subOptions
        }else if(row == 3){
          this.form.subId3 = null
          this.form.subId4 = null
          this.form.finaAbstract = null
          this.sub3Options = subOptions
          //设置经办人
          //初始化经办人
          var cashOpter = this.dict.type.cash_opter
          this.cashOpterUse = []
          this.cashOpter1 = []
          this.cashOpter2 = []
          this.cashOpter3 = []
          var cashOpterTemp = []
            // console.log("opt>>>>>",JSON.stringify(cashOpter.length))
          for(let i=0;i<cashOpter.length;i++){
            var opt = cashOpter[i]

            console.log("opt.label>>>>>",opt.label)
            if(opt.label === "MK9813"){
              this.cashOpter1.push(opt)
            }
            if(opt.label === "MK5255"){
              this.cashOpter1.push(opt)
            }
            if(opt.label === "JM-XGM"){
              this.cashOpter1.push(opt)
            }
            if(opt.label === "MKcode"){
              this.cashOpter1.push(opt)
            }
            if(opt.label === "MK-XGM"){
              this.cashOpter1.push(opt)
            }

            if(opt.label === "SMK6217"){
              this.cashOpter2.push(opt)
            }
            if(opt.label === "SJM3649"){
              this.cashOpter2.push(opt)
            }
            if(opt.label === "MKXJ"){
              this.cashOpter2.push(opt)
            }
            if(opt.label === "JMXJ"){
              this.cashOpter2.push(opt)
            }


            if(opt.label === "海洋科技" || opt.label === "JM1781"){
              this.cashOpter3.push(opt)
            }
          }


          // console.log("cashOpter1>>>>>",cashOpterTemp)
          // console.log("cashOpter1>>>>>",this.cashOpter1)
          // console.log("cashOpter2>>>>>",this.cashOpter2)
          // console.log("cashOpter1>>>>>",this.cashOpter3)


          if(subName.indexOf("1号") != -1){
            this.cashOpterUse = this.cashOpter1
          }else if(subName.indexOf("2号") != -1){
            this.cashOpterUse = this.cashOpter2
          }else if(subName.indexOf("借") != -1 || subName.indexOf("还") != -1){
            this.cashOpterUse = this.cashOpter3
          }

          // console.log("cashOpterUse>>>>>",this.cashOpterUse)

        }else if(row == 4){
          this.form.subId4 = null
          this.form.finaAbstract = null
          this.sub4Options = subOptions
        }else if(row == 5){
          this.form.finaAbstract = null
          this.finaAbstractOptions = subOptions
          // console.log("this.finaAbstractShow",this.finaAbstractShow)
          if(subOptions != null && subOptions.length > 0){//存在用途
          // console.log("subOptions",subOptions,"存在用途")
            this.finaAbstractShow = true
            this.rules.finaAbstract[0].required = true
          }else{// 不需要录入用途
          // console.log("subOptions",subOptions,"不需要录入用途")
            this.finaAbstractShow = false
            this.rules.finaAbstract[0].required = false
          }
          //判断是否存在需要录入客户名称

          if(this.form.subName4 != undefined && this.form.subName4 != null && this.form.subName4 != ""){
            var subNameTemp = this.form.subName4;
            // console.log("subNameTemp",subNameTemp)
            // console.log("this.cusNameShow",this.cusNameShow)
            if(subNameTemp.indexOf("客户") != -1){
            // console.log("subNameTemp",subNameTemp,"需要录入客户")
              this.cusNameShow = true
              this.rules.cusName[0].required = true
            }else{
            // console.log("subNameTemp",subNameTemp,"不需要录入客户")
              this.cusNameShow = false
              this.rules.cusName[0].required = false
            }
          }

        }

      },

      /** 搜索根据上一级获取对应下一级列表 */
      getSubListBySubIdSearch(row,subId){
        var data = this.subAllOptions
        var subOptions = []
        for(let i=0;i<data.length;i++){
          var item = data[i]
          var orderNum = item.orderNum
          if(item.parentId == subId){
            subOptions.push(item)
          }
        }

        if(row == 2){

          this.queryParams.subId2 = null
          this.sub2Options = subOptions
        }else if(row == 3){
          this.queryParams.subId3 = null
          this.sub3Options = subOptions
        }else if(row == 4){
          this.queryParams.subId4 = null
          this.sub4Options = subOptions
        }else if(row == 5){
          this.queryParams.finaAbstract = null
          this.finaAbstractOptions = subOptions
        }

      },
      setOperatorName(cashOpte,finaOperatorName){
        this.cashOpter = cashOpte
        // for(let i=0;i<cashOpte.length;i++){
        //   var item = cashOpte[i]
        //   if(item.value == finaOperatorName){
        //     this.form.finaOperatorId = item.value
        //     this.form.finaOperatorName = item.label
        //     break
        //   }
        // }
        // // $forceUpdate()
        // console.log("this.form.finaOperatorId>>>",this.form.finaOperatorId)
        // console.log("this.form.finaOperatorName>>>",this.form.finaOperatorName)
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          finaId: null,
          finaCode: null,
          finaDate: null,
          subId1: null,
          subName1:null,
          subId2: null,
          subName2:null,
          subId3: null,
          subName3:null,
          subId4: null,
          subName4:null,
          orderNum: null,
          finaAbstract: null,
          finaOperatorId: null,
          finaIn: null,
          finaOut: null,
          finaBalance: null,
          remark: null,
          status: "0",
          delFlag: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null
        };
        this.autoGenFlag = false;
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.finaId)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加日记账记录";
        this.optType = "add";
        // this.form.finaOperatorName = "海洋科技"
        // console.log(">>>>>>>>",JSON.stringify(this.dict.type.cash_opter))
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        this.optType = "edit";
        const finaId = row.finaId || this.ids
        getCash(finaId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改日记账记录";
          console.log("this.form>>>",this.form)
          if(this.form.subId1 == 101){//应收
            this.inShow = true
            this.outShow = false
            this.rules.finaIn[0].required = true
            this.rules.finaOut[0].required = false
          }else if(this.form.subId1 == 102){// 应付
            this.inShow = false
            this.outShow = true
            this.rules.finaIn[0].required = false
            this.rules.finaOut[0].required = true
          }


          if(this.form.subId4 != undefined && this.form.subId4 != null && this.form.subId4 != ""){

            // console.log("subOptions",subOptions,"存在用途")
            this.finaAbstractShow = true
            this.rules.finaAbstract[0].required = true

            var subNameTemp = this.form.subName4;
            // console.log("subNameTemp",subNameTemp)
            // console.log("this.cusNameShow",this.cusNameShow)
            if(subNameTemp.indexOf("客户") != -1){
            // console.log("subNameTemp",subNameTemp,"需要录入客户")
              this.cusNameShow = true
              this.rules.cusName[0].required = true
            }else{
            // console.log("subNameTemp",subNameTemp,"不需要录入客户")
              this.cusNameShow = false
              this.rules.cusName[0].required = false
            }
          }else{// 不需要录入用途
          // console.log("subOptions",subOptions,"不需要录入用途")
            this.finaAbstractShow = false
            this.rules.finaAbstract[0].required = false
          }
        });
      },
      /** 提交按钮 */
      submitForm() {
        if(this.inShow){
          if (!/^\d+(\.\d{0,2})?$/.test(this.form.finaIn)) {
            this.$modal.msgError('请输入正确的收入金额（最多只能保留两位小数）')
            return;
          }
        }

        if(this.outShow){
          if (!/^\d+(\.\d{0,2})?$/.test(this.form.finaOut)) {
            this.$modal.msgError('请输入正确的支出金额（最多只能保留两位小数）')
            return;
          }
        }

        if(this.dict != undefined && this.dict != null){
          var cashOpte = this.dict.type.cash_opter
          var finaOperatorIdTemp = this.form.finaOperatorName
          for(let i=0;i<cashOpte.length;i++){
            var item = cashOpte[i]
            if(item.value == finaOperatorIdTemp){
              this.form.finaOperatorId = item.value
              this.form.finaOperatorName = item.label
              break
            }
          }
        }
        // console.log("this.form.finaOperatorId>>>",this.form.finaOperatorId)
        // console.log("this.form.finaOperatorName>>>",this.form.finaOperatorName)
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.finaId != null) {
              updateCash(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addCash(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const finaIds = row.finaId || this.ids;
        this.$modal.confirm('是否确认删除日记账记录编号为"' + finaIds + '"的数据项？').then(function() {
          return delCash(finaIds);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('/mes/fina/cash/export', {
          ...this.queryParams
        }, `cash_${new Date().getTime()}.xlsx`)
      },
      //自动生成物料编码
      handleAutoGenChange(autoGenFlag){
        // debugger;
        if(autoGenFlag){
          genCode('FINA_CODE').then(response =>{
            // console.log("response>>>>>>",response)
            this.form.finaCode = response;
          });
         }else{
            this.form.finaCode = null;
         }
      },
      cellStyle({ row, column, rowIndex, columnIndex }) {
        if (column.property === 'subName3' ) {
          if (row.subName3 === '海洋科技') {
            return 'color: red;';
          }
        }
        if (column.property === 'subName3' ) {
          if (row.subName3 === '海洋科技') {
            return 'color: red;';
          }
        }
        if (column.property === 'subName4' ) {
          if (row.subName4 === '海洋科技') {
            return 'color: red;';
          }
        }
        if (column.property === 'finaOperatorName' ) {
          if (row.finaOperatorName === '海洋科技') {
            return 'color: red;';
          }
        }

        // if (column.property === 'subName3' || column.property === 'finaOperatorName' || column.property === 'subName4' ) {
        //   if (row.finaOperatorName === '海洋科技' || row.subName3 === '海洋科技' || row.subName4 === '海洋科技') {
        //     return 'color: red;';
        //   }
        // }

      },
      tableRowClassName({ row, rowIndex }) {
        if (rowIndex === 0) {
          return 'row1';
        } else if (rowIndex >= 1 && rowIndex <= 7 ) {
          return "row2";
        } else if (rowIndex >= 8 && rowIndex <= 12 ) {
          return "row3";
        }
      },
      //合并单元格
      arraySpanMethod({ row, column, rowIndex, columnIndex }) {

        if (columnIndex === 5) {

          if([1,2,3,4,5,6,7].includes(rowIndex)){
            if(rowIndex === 1 ){
              return {
                 rowspan: 7,
                 colspan: 1
               };
            }else{
              return {
                 rowspan: 0,
                 colspan: 0
               };
            }

          }else if([8,9,10,11,12].includes(rowIndex)){
            //这里提一句，从哪一格开始合并显示的就是哪一格,具体看数据中的father属性
              if(rowIndex === 8 ){
                return {
                   rowspan: 5,
                   colspan: 1
                 };
              }else{
                //这句一定要加，被合并的表格需要返回0，0  不然格式可能会错乱
                return {
                   rowspan: 0,
                   colspan: 0
                 };
              }
          }else{
            return {
               rowspan: 1,
               colspan: 1
             };
          }
        }

      },

      // 收入金额验证表达式
      isInMoney(rule,value,callback){
        const { required } = rule
          if(!required){
            console.log("无需收入>>>>>>>>")
            return
          }
          if (value === '') {
            if (required) callback('请输入收入金额')
            else callback()
          } else if (!/^\d+(\.\d{0,2})?$/.test(value)) {
            callback('请输入正确的收入数值（最多只能保留两位小数）')
          } else if (value > 10000000) {
            callback('单次收入不得大于10000000')
          } else {
            callback()
          }
      },
      // 支出金额验证表达式
      isOutMoney(rule,value,callback){
        const { required } = rule

          if(!required){
            console.log("无需支出>>>>>>>>")
            return
          }
          if (value === '') {
            if (required) callback('请输入支出金额')
            else callback()
          } else if (!/^\d+(\.\d{0,2})?$/.test(value)) {
            callback('请输入正确的支出数值（最多只能保留两位小数）')
          } else if (value > 10000000) {
            callback('单次支出不得大于10000000')
          } else {
            value = 0-value
            callback()
          }
      }
    }
  };
</script>

<style>
.el-table .row1 {
  background: #EAFAF1;
}
.el-table .row2 {
  background: #FFFFE0;
}
.el-table .row3 {
  background: #EBF5FB;
}
.el-table .row4 {
  background: #FFFFE0;
}
</style>
